home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / teco.zip / ECHO.C < prev    next >
C/C++ Source or Header  |  1986-07-15  |  980b  |  53 lines

  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. static char last='\0';
  6. static char this='\0';
  7.  
  8. echo(c) /* Echo char appropriately on console */
  9. {
  10. #include "teco.h"
  11.  
  12.     if (cancel) return;            /* Skip if ^O sent */
  13.     this=toascii(c);            /* Mask off parity */
  14.     if (this == 27) {            /* Check for <ESC> */
  15.         this='$';            /*  ..if so echo $ */
  16.     } else {                /* Else process it */
  17.         if (iscntrl(this)) {
  18.             if (this == 10) {
  19.                 if (last == 13) {
  20.                     last=this;
  21.                     return;
  22.                 } else {
  23.                     fprintf(stderr,"\n");
  24.                     goto check;
  25.                 }
  26.             } else {
  27.                 if (this == 13) {
  28.                     fprintf(stderr,"\n");
  29.                     goto check;
  30.                 }
  31.                 if (this == 9) {
  32.                     fprintf(stderr,"\11");
  33.                     goto check;
  34.                 } else {
  35.                     fprintf(stderr,"\^");
  36.                     this=this+64;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     fprintf(stderr,"%c",this);
  42.     last=this;
  43.     return;
  44.  
  45. check:    last=this;
  46.     if (kbhit()) {
  47.         if (15 == toascii(getch())) {
  48.             cancel=1;
  49.             fprintf(stderr,"\^O\n");
  50.         }
  51.     }
  52. }
  53.